<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>!window.jQuery && document.write('<script src="{{=URL(request.application,'static','js/jquery.js')}}"><\/script>')</script>

{{

response.files.append(URL(request.application,'static/css','jquery.jgrowl.css'))
response.files.append(URL(request.application,'static/css','jgrowl.i2p.css'))
response.files.append(URL(request.application,'static/js','jquery.jgrowl_minimized.js'))

#response.files.insert(0,URL(r=request,c='static',f='js/modernizr-1.5.min.js'))
#response.files.insert(1,URL(r=request,c='static',f='js/jquery-1.4.2.min.js'))

if is_user_an_admin():	
    if i2p.config.editor=="CKeditor":		
		response.files.append(URL(r=request,c='static',f='js/ckeditor/ckeditor.js'))
		response.files.append(URL(r=request,c='static',f='js/ckeditor/adapters/jquery.js'))
		response.files.append(URL(r=request,c='static',f='js/jquery-ui-1.8.4.custom.min.js'))
	elif i2p.config.editor=="elRTE":
		response.files.append(URL(r=request,c='static',f='js/elrte/js/ui-themes/smoothness/jquery-ui-1.8.5.custom.css'))
		response.files.append(URL(r=request,c='static',f='js/elrte/css/elrte.full.css'))
		response.files.append(URL(r=request,c='static',f='js/elrte/js/jquery-ui-1.8.5.custom.min.js'))
		response.files.append(URL(r=request,c='static',f='js/elrte/js/elrte.min.js'))
		#response.files.append(URL(r=request,c='static',f='js/elrte/js/i18n/elrte.ru.js'))		
	pass		
	
	response.files.append(URL(r=request,c='static',f='css/i2p.admin.css'))
pass

#load the most common syntax highligh add what you need
if i2p.config.syntax_highlight:
	response.files.append(URL(r=request,c='static',f='js/syntaxhighlighter/scripts/shCore.js'))
	response.files.append(URL(r=request,c='static',f='js/syntaxhighlighter/scripts/shBrushJScript.js'))
	response.files.append(URL(r=request,c='static',f='js/syntaxhighlighter/scripts/shBrushPython.js'))
	response.files.append(URL(r=request,c='static',f='js/syntaxhighlighter/scripts/shBrushCss.js'))
	response.files.append(URL(r=request,c='static',f='js/syntaxhighlighter/styles/shCoreDefault.css'))	
pass


for _item in response.meta or []:}}
     <meta name="{{=_item}}" content="{{=response.meta[_item]}}" />{{
pass
for _k,_file in enumerate(response.files or []):
  if _file in response.files[:_k]:
     continue
  elif _file[-4:].lower()=='.css':}}
     <link href="{{=_file}}" rel="stylesheet" type="text/css" />{{
  elif _file[-3:].lower()=='.js':}}
     <script src="{{=_file}}" type="text/javascript"></script>{{
  pass
pass
}}

<!-- For the less-enabled mobile browsers like Opera Mini -->
<link rel="stylesheet" media="handheld" href="{{=URL(request.application,'static','css/handheld.css')}}">

{{if i2p.config.syntax_highlight:}}
	<script type="text/javascript">SyntaxHighlighter.all();</script>
{{pass}}

<script type="text/javascript" charset="utf-8"><!--

function popup(url) {
  newwindow=window.open(url,'name','height=400,width=600');
  if (window.focus) newwindow.focus();
  return false;
}
function collapse(id) { jQuery('#'+id).slideToggle(); }
function fade(id,value) { if(value>0) jQuery('#'+id).hide().fadeIn('slow'); else jQuery('#'+id).show().fadeOut('slow'); }
function ajax(u,s,t) {
    query = '';
    if (typeof s == "string") {
        d = jQuery(s).serialize();
        if(d){ query = d; }
    } else {
        pcs = [];
        for(i=0; i<s.length; i++) {
            q = jQuery("#"+s[i]).serialize();
            if(q){pcs.push(q);}
        }
        if (pcs.length>0){query = pcs.join("&");}
    }
    jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" + t).html(msg); } } }); 
}
String.prototype.reverse = function () { return this.split('').reverse().join('');};
function web2py_ajax_init() {
  jQuery('.hidden').hide();
  jQuery('.error').hide().slideDown('slow');
  jQuery('.flash').click(function() { jQuery(this).fadeOut('slow'); return false; });
  jQuery('input.integer').keyup(function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});
  jQuery('input.double').keyup(function(){this.value=this.value.reverse().replace(/[^0-9\-\.]|[\-](?=.)|[\.](?=[0-9]*[\.])/g,'').reverse();});
  jQuery("input[type='checkbox'].delete").each(function(){jQuery(this).click(function() { if(this.checked) if(!confirm("{{=T('Sure you want to delete this object?')}}")) this.checked=false; });});
  try {jQuery("input.date").focus( function() {Calendar.setup({
     inputField:this.id, ifFormat:"{{=T('%Y-%m-%d')}}", showsTime:false
  }); }); } catch(e) {};
  try { jQuery("input.datetime").focus( function() {Calendar.setup({
     inputField:this.id, ifFormat:"{{=T('%Y-%m-%d %H:%M:%S')}}", showsTime: true,timeFormat: "24"
  }); }); } catch(e) {};
  try { jQuery("input.time").clockpick({
      starthour:0, endhour:23, showminutes:true, military:true
  }); } catch(e) {};
};
jQuery(document).ready(function(){
      
   var flash = jQuery('.flash').html();
   if(flash!='') {ShowFlash(flash,1)}   
   
   web2py_ajax_init();   
   {{if WIDGETS_AJAX:}}
   		Load_Widgets();
   {{pass}}
   
   });

function web2py_trap_form(action,target) {
   jQuery('#'+target+' form').each(function(i){
      var form=jQuery(this);
      if(!form.hasClass('no_trap'))
        form.submit(function(obj){
         jQuery('.flash').hide().html('');
         web2py_ajax_page('post',action,form.serialize(),target);
         return false;
      });
   });
}

function web2py_ajax_page(method,action,data,target) {
  jQuery.ajax({'type':method,'url':action,'data':data,
    'beforeSend':function(xhr){
      xhr.setRequestHeader('web2py-component-location',document.location);
      xhr.setRequestHeader('web2py-component-element',target);},
    'complete':function(xhr,text){
      command=xhr.getResponseHeader('web2py-component-command');
      if(command) eval(command);
      flash=xhr.getResponseHeader('web2py-component-flash');
      if(flash) jQuery('.flash').html(flash).slideDown();
      },
    'success': function(text) {
      jQuery('#'+target).html(text);
      web2py_trap_form(action,target);
      web2py_ajax_init();
      }
    });
}
function web2py_component(action,target) {
    jQuery(document).ready(function(){ web2py_ajax_page('get',action,null,target); });
}
//--></script>
